import $V from './$V';

export default function mfi(high, low, close, volume, length) {
    let MFIValue = $V.init(high.length,0);
    let DiffofTP = $V.init(high.length,0);
    let TP = $V.div_constant($V.add($V.add(high,low),close),3);
    DiffofTP = $V.copy_by_index(DiffofTP,2,$V.sub($V.subv(TP,2,TP.length),$V.subv(TP,1,TP.length-1)));
    let MF = $V.mul(TP,volume);
    MFIValue = $V.set_by_index(MFIValue,$V.arange(1,length),50);
    for(let i = length ;i < high.length;i++){
        let Temp = $V.subv(MF,i-length,i);
        let PMF = $V.vector_of_index(Temp,$V.where($V.subv(DiffofTP,i-length,i),">",0));
        MFIValue[i] = $V.sum(PMF)/$V.sum(Temp)*100;
    }
    return MFIValue;
}
